<!DOCTYPE html>
<html>

<head>
    <meta charset="utf-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
</head>

<body>
    <h1>尚硅谷</h1>
    <button>点击获取用户数据</button>
    <script type="text/javascript">
        const btn = document.querySelector("button");

        btn.onclick = function () {
            const xhr = new XMLHttpRequest();

            xhr.open("GET", "/data");

            xhr.send();

            xhr.onreadystatechange = function () {
                if (xhr.readyState === 4) {
                    if (xhr.status >= 200 && xhr.status < 300) {
                            console.log(xhr.response);
                    };
                };

            };


        }



    </script>
</body>

</html>